/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.suspend.b.b;

import android.content.Context;
import android.os.AsyncTask;
import android.text.TextUtils;
import com.qihoo.gamecenter.sdk.suspend.c.a;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class j extends AsyncTask {
    private Context a;
    private String b;
    private d c;
    private boolean d;

    public j(Context paramContext, String paramString, d paramd, boolean paramBoolean) {
        this.a = paramContext;
        this.b = paramString;
        this.c = paramd;
        this.d = paramBoolean;
    }

    protected e a(List[] paramArrayOfList) {
        if ((TextUtils.isEmpty(this.b)) || (paramArrayOfList == null) || (paramArrayOfList.length < 1))
            return null;
        com.qihoo.gamecenter.sdk.suspend.b.b.a("UploadLocalAppPackagesTask",
                "--------------------------------start to upload apps to server.--------------------------");
        String str = h.a(this.a, this.b, paramArrayOfList[0]);
        if (str == null)
            return null;
        return new e(str);
    }

    protected void a(e parame) {
        super.onPostExecute(parame);
        if (parame == null)
            return;
        com.qihoo.gamecenter.sdk.suspend.b.b.a("UploadLocalAppPackagesTask", "onPostExecute:" + parame.d);
        if (this.c != null)
            this.c.a(parame);
        if (this.d) {
            a.a(this.a, parame.c);
            com.qihoo.gamecenter.sdk.suspend.remote.b.b().e();
        }
        else {
            if (TextUtils.isEmpty(parame.c))
                return;
            try {
                JSONObject localJSONObject1 = new JSONObject(parame.c);
                String str1 = a.a(this.a);
                JSONObject localJSONObject2 = null;
                JSONArray localJSONArray1 = null;
                if (!(TextUtils.isEmpty(str1))) {
                    localJSONObject2 = new JSONObject(str1);
                    if (localJSONObject2 != null)
                        localJSONArray1 = localJSONObject2.getJSONArray("pkg");
                }
                if (localJSONObject2 == null)
                    localJSONObject2 = new JSONObject();
                if (localJSONArray1 == null)
                    localJSONArray1 = new JSONArray();
                if (localJSONObject1.has("pkg")) {
                    JSONArray localJSONArray2 = localJSONObject1.getJSONArray("pkg");
                    if ((localJSONArray2 != null) && (localJSONArray2.length() > 0)) {
                        int i = localJSONArray2.length();
                        String str2 = "";
                        for (int j = 0; j < i; ++j) {
                            str2 = localJSONArray2.getString(j);
                            if ((TextUtils.isEmpty(str2)) || (str1.indexOf(str2) != -1))
                                continue;
                            localJSONArray1.put(str2);
                            com.qihoo.gamecenter.sdk.suspend.remote.b.b().c(str2);
                        }
                    }
                }
                localJSONObject2.put("pkg", localJSONArray1);
                a.a(this.a, localJSONObject2.toString());
            } catch (JSONException localJSONException) {
                localJSONException.printStackTrace();
            }
        }
    }
}